﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using System.IO;
using System.Xml;
using BLL;
using DAL;
using Models;
using System.Data;
using Web.Old_App_Code;
using System.Collections;
public partial class cn_points_for_info : System.Web.UI.Page
{

    protected FreightWayManager fwm = new FreightWayManager();
    protected GoodsEntitysManager gem = new GoodsEntitysManager();
    protected GoodsEntitysSpecificationsManager gesm = new GoodsEntitysSpecificationsManager();
    protected GoodGalleryManager ggm = new GoodGalleryManager();

    protected PointsForManager pfm = new PointsForManager();
    protected string postscriptXmlPath = "/cn/xml/order_postscript.xml";
    protected RegionManager rm = new RegionManager();
    protected ShoppingCartManager scm = new ShoppingCartManager();
    protected UserAddressManager uam = new UserAddressManager();
    protected string xmlPath = "/cn/xml/payment.xml";

    // Methods
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HttpContext.Current.Session["user"] == null)
        {
            base.Response.Redirect("web_login.html?ru=" + HttpContext.Current.Request.Url.PathAndQuery.Replace("aspx", "html"));
        }
    }

    protected StringBuilder PointsForBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            if (this.Session["user"] == null)
            {
                return builder;
            }
            DataTable pointsForById = this.pfm.GetPointsForById(Convert.ToInt32(base.Request.QueryString["id"]));
            if (pointsForById.Rows.Count > 0)
            {
                DataRow row = pointsForById.Rows[0];
                builder.AppendLine("<tr>");
                builder.AppendLine(string.Concat(new object[] { "<td><a href=\"/cn/points_for.html?id=", row["id"], "\" target=\"_blank\"><img src=\"", row["image"], "\" alt=\"", row["name"], "\" /></a></td>" }));
                builder.AppendLine(string.Concat(new object[] { "<td><a href=\"/cn/points_for.html?id=", row["id"], "\" target=\"_blank\">", row["name"], "</a></td>" }));
                builder.AppendLine("<td>" + row["exchangePoints"] + "</td>");
                builder.AppendLine("<td>1</td>");
                builder.AppendLine("</tr>");
                return builder;
            }
            builder.AppendLine("<tr>");
            builder.AppendLine("<td colspan=\"4\" style=\"text-align: center; color: #ff0000;\">兑换清单目前没有加入任何兑换商品</td>");
            builder.AppendLine("</tr>");
        }
        catch
        {
        }
        return builder;
    }

    protected StringBuilder PostscriptBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            XmlDocument document = new XmlDocument();
            document.Load(base.Server.MapPath(this.postscriptXmlPath));
            XmlElement element = document.SelectSingleNode("postscript/set") as XmlElement;
            builder.AppendLine("<h6>附言：</h6>");
            builder.AppendLine("<p><textarea id=\"txtaPostscript\" cols=\"" + element.GetAttribute("cols") + "\" rows=\"" + element.GetAttribute("rows") + "\">" + element.GetAttribute("value") + "</textarea><span id=\"spPostscript\"></span></p>");
        }
        catch
        {
        }
        return builder;
    }

    protected StringBuilder ProvincesBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            builder.AppendLine("<p><label for=\"selectProvinces\">省份/直辖市：</label>");
            builder.AppendLine("<select id=\"selectProvinces\">");
            builder.AppendLine("<option value=\"0\" selected=\"selected\">请选择...</option>");
            DataTable regionByParentRegionAndLanguageVersion = this.rm.GetRegionByParentRegionAndLanguageVersion(0, "zh-CN");
            foreach (DataRow row in regionByParentRegionAndLanguageVersion.Rows)
            {
                builder.AppendLine(string.Concat(new object[] { "<option value=\"", row["id"], "\">", row["regionName"], "</option>" }));
            }
            builder.AppendLine("</select><span id=\"spanCity\" style=\"color: #000000;\"></span><span id=\"spProvinces\">*</span></p>");
        }
        catch
        {
        }
        return builder;
    }

    protected StringBuilder UserAddressBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            if (this.Session["user"] == null)
            {
                return builder;
            }
            builder.AppendLine("<table class=\"firsttable\">");
            DataTable userAddressByUser = this.uam.GetUserAddressByUser((this.Session["user"] as User).Id);
            foreach (DataRow row in userAddressByUser.Rows)
            {
                builder.AppendLine("<tr>");
                builder.AppendLine(string.Concat(new object[] { "<td><input type=\"radio\" name=\"userAddress\" value=\"", row["id"], "\" onclick=\"isDisplayUserAddress('", row["region"].ToString().Split(new char[] { ',' }).GetValue(0), "');\" ", (Convert.ToInt32(row["isDefault"]) == 1) ? "checked='checked'" : "", " />", row["consignee"], "</td>" }));
                builder.AppendLine(string.Concat(new object[] { "<td>", (row["region"].ToString().IndexOf(",") != -1) ? row["region"].ToString().Split(new char[] { ',' }).GetValue(0) : row["region"].ToString(), (row["region"].ToString().IndexOf(",") != -1) ? row["region"].ToString().Split(new char[] { ',' }).GetValue(1) : "", row["address"], "</td>" }));
                builder.AppendLine("<td>" + row["zipcode"] + "</td>");
                builder.AppendLine("<td>" + row["mobile"] + "</td>");
                builder.AppendLine("<td>" + row["telephone"] + "</td>");
                builder.AppendLine("</tr>");
            }
            builder.AppendLine("</table>");
        }
        catch
        {
        }
        return builder;
    }

}